package com.push.alipush;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.alibaba.sdk.android.push.popup.PopupNotifyClick;
import com.alibaba.sdk.android.push.popup.PopupNotifyClickListener;

import java.util.HashMap;
import java.util.Map;

/**
 * 手机锁屏状态下，展示提示
 */
public class LockScreenActivity extends Activity {

    private PopupNotifyClick mPopupNotifyClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //四个标志位顾名思义，分别是锁屏状态下显示，解锁，保持屏幕长亮，打开屏幕。这样当Activity启动的时候，它会解锁并亮屏显示。
        Window win = getWindow();
        win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED //锁屏状态下显示
//                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD //解锁
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕长亮
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //打开屏幕

        Drawable wallPaper = WallpaperManager.getInstance( this).getDrawable();

        View view = new View(this);
        view.setBackground(wallPaper);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        setContentView(view);

        mPopupNotifyClick = new PopupNotifyClick(new PopupNotifyClickListener() {
            public void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
//                Log.w("warehouse", "title = " + title);
//                Log.w("warehouse", "summary = " + summary);
//                if(extMap != null) {
//                    Log.w("warehouse", extMap.toString());
//                }
                HashMap<String, Object> map = new HashMap<>();
                map.put("title", title);
                map.put("content", summary);
                map.put("extra", extMap);
//        AlipushFlutterPlugin.instance.runMainThread(map, null, "onNotificationOpened");
                AlipushFlutterPlugin.instance.runMainThread(map, null, "onOpenNotification");
                finish();
            }
        });
        mPopupNotifyClick.onCreate(this, this.getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        mPopupNotifyClick.onNewIntent(intent);
    }
}
